/**
 * Created by Jehuty on 16/11/30.
 */
$(function () {
    banner();
    submit()
})

//背景轮播图
function banner() {
    $(window).on("resize",function () {
        $(".background-img").css("height",$(window).height()+"px");
    }).trigger("resize");
    $(".background-img").css({ opacity: 1});
    $.backstretch([
        "./images/login/1.jpg",
        "./images/login/2.jpg",
        "./images/login/3.jpg",
    ], { duration: 2000, fade: 750 });
}

//submit
function submit() {
    $("#submit").on("click",function () {
        var username = $("#username").val();
        //判断有没有输入
        if($("#username").val()&& $("#password").val()){
            var send = {username:username,
                        password:$("#password").val()}
            //发送请求
            $.ajax({
                url:myUrl.url3,
                type:"post",
                data:send,
                success:function (data) {
                    if(data.code!=1){
                        throwError(data.msg);
                    }else{
                        throwError("登录成功,即将跳转");
                        setTimeout(function () {
                            location.href = "./sbadmin.html?un="+username;
                        },2000)
                    }
                }
            })
        }else{
            throwError("请输入账号密码");
        }
        return false;
    })

    /*抛出提示函数*/
    function throwError(text) {
        $(".error").text(text).fadeIn().delay(1000).fadeOut();
    }
}